﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using Microsoft.EntityFrameworkCore;
using Model.viewModel;
using Dal.Iterfease;

namespace Dal.infDal
{
    public class commodDal : Icommod
    {
        private readonly AppDbContext _appDbContext;

        public commodDal(AppDbContext appDbContext)
        {
            _appDbContext = appDbContext;
        }

        /// <summary>
        /// 首页商品展示
        /// </summary>
        /// <returns></returns>
        public List<CommodModel> ShowCommodl(int? Cid)
        {
            var q = from a in _appDbContext.commodityInfos
                    select new CommodModel
                    {
                        Cid = a.Cid,
                        Cname = a.Cname,
                        Cversions = a.Cversions,
                        Cprice = a.Cprice,
                        Ccolor = a.Ccolor,
                        Cimg = "http://localhost:16673/StaticFiles/" + a.Cimg,
                        Ctxt = a.Ctxt,
                        Cimgs = "http://localhost:16673/StaticFilesBig/" + a.Cimgs,
                    };
            if (Cid != null)
            {
                q = q.Where(u => u.Cid == Cid);
            }
            return q.ToList();
        }

        /// <summary>
        /// 详情轮播图
        /// </summary>
        /// <param name="Cid"></param>
        /// <returns></returns>
        public List<ImgsModel> showimgs(int Cid)
        {
            var sql = from a in _appDbContext.imgsInfo
                      join b in _appDbContext.commodityInfos on a.Mcid equals b.Cid
                      where Cid == b.Cid
                      select new ImgsModel
                      {
                          Mid = a.Mid,
                          Mnaem = "http://localhost:16673/StaticFilesinfo/" + a.Mnaem,
                          Mcid = a.Mcid,
                      };

            return sql.ToList(); ;
        }


    }
}
